﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Threading;
using System.IO;
using UHFDemo;

namespace SourceMind
{
    public partial class R2000UartDemo : Form
    {

        private Reader.ReaderMethod reader;
        OracleHelper dbconn = new OracleHelper();//数据库连接用

        private ReaderSetting m_curSetting = new ReaderSetting();
        private InventoryBuffer m_curInventoryBuffer = new InventoryBuffer();
        private OperateTagBuffer m_curOperateTagBuffer = new OperateTagBuffer();
        private OperateTagISO18000Buffer m_curOperateTagISO18000Buffer = new OperateTagISO18000Buffer();

        //盘存操作前，需要先设置工作天线，用于标识当前是否在执行盘存操作
        private bool m_bInventory = false;
        //标识是否统计命令执行时间，当前仅盘存命令需要统计时间
        private bool m_bReckonTime = false;
        //实时盘存锁定操作
        private bool m_bLockTab = false;
        //ISO18000标签连续盘存标识
        private bool m_bContinue = false;
        //是否显示串口监控数据
        private bool m_bDisplayLog = false;
        //记录ISO18000标签循环写入次数
        private int m_nLoopTimes = 0;
        //记录ISO18000标签写入字符数
        private int m_nBytes = 0;
        //记录ISO18000标签已经循环写入次数
        private int m_nLoopedTimes = 0;
        //实时盘存次数
        private int m_nTotal = 0;
        //列表更新频率
        private int m_nRealRate = 20;
        //记录快速轮询天线参数
        private byte[] m_btAryData = new byte[18];
        //4 ant
        private byte[] m_btAryData_4 = new byte[10];
        //记录快速轮询总次数
        private int m_nSwitchTotal = 0;
        private int m_nSwitchTime = 0;

        private int m_nReceiveFlag = 0;

        private volatile bool m_nPhaseOpened = false;
        private volatile bool m_nSessionPhaseOpened = false;



        public R2000UartDemo()
        {
            InitializeComponent();
            this.DoubleBuffered = true;

           
        }

        private void R2000UartDemo_Load(object sender, EventArgs e)
        {
            //初始化访问读写器实例
            reader = new Reader.ReaderMethod();

            //回调函数
            reader.AnalyCallback = AnalyData;
            reader.ReceiveCallback = ReceiveData;
            reader.SendCallback = SendData;

           


            //初始化连接读写器默认配置
            cmbComPort.SelectedIndex = 0;
            cmbBaudrate.SelectedIndex = 1;


            gBoxBind.Enabled = false;
            gBoxAccessce.Enabled = false;
            gBoxWriteRead.Enabled = false;

        }

        private void ReceiveData(byte[] btAryReceiveData)
        {
            if (m_bDisplayLog)
            {
                string strLog = CCommondMethod.ByteArrayToString(btAryReceiveData, 0, btAryReceiveData.Length);

                lrtxtLog.AppendText(strLog + "\n");
            }
        }

        private void SendData(byte[] btArySendData)
        {
            if (m_bDisplayLog)
            {
                string strLog = CCommondMethod.ByteArrayToString(btArySendData, 0, btArySendData.Length);

                lrtxtLog.AppendText(strLog + "\n");
            }
        }

        private void AnalyData(Reader.MessageTran msgTran)
        {
            m_nReceiveFlag = 0;
            if (msgTran.PacketType != 0xA0)
            {
                return;
            }
            switch (msgTran.Cmd)
            {
                case 0x72:
                    ProcessGetFirmwareVersion(msgTran);
                    break;
                case 0x81:
                    ProcessReadTag(msgTran);
                    break;
                case 0x85:
                    ProcessSetAccessEpcMatch(msgTran);
                    break;
                case 0x89:
                    ProcessGetRFIDEpc(msgTran);
                    break;
                case 0x82:
                    ProcessWriteTag(msgTran);
                    break;
            }
        }

        private delegate void RefreshReadSettingUnsafe(byte btCmd);
        private void RefreshReadSetting(byte btCmd)
        {
            if (this.InvokeRequired)
            {
                RefreshReadSettingUnsafe InvokeRefresh = new RefreshReadSettingUnsafe(RefreshReadSetting);
                this.Invoke(InvokeRefresh, new object[] { btCmd });
            }
            else
            {
                //htxtReadId.Text = string.Format("{0:X2}", m_curSetting.btReadId);
                switch (btCmd)
                {
                    
                    
                    case 0x72:
                        {
                            String result = m_curSetting.btMajor.ToString() + "." + m_curSetting.btMinor.ToString();
                            lrtxtLog.AppendText(result + "\n");
                        }
                        break;
                    
                    
                    
                }
            }
        }


        private void SetButtonBold(Button btnBold)
        {
            Font oldFont = btnBold.Font;
            Font newFont = new Font(oldFont, oldFont.Style ^ FontStyle.Bold);
            btnBold.Font = newFont;
        }

        //处理串口连接读写器
        private void btnConnectRs232_Click(object sender, EventArgs e)
        {
            //处理串口连接读写器
            string strException = string.Empty;
            string strComPort = cmbComPort.Text;
            int nBaudrate = Convert.ToInt32(cmbBaudrate.Text);

            int nRet = reader.OpenCom(strComPort, nBaudrate, out strException);
            if (nRet != 0)
            {
                string strLog = "连接读写器失败，失败原因： " + strException;
                lrtxtLog.AppendText(strLog+"\n");

                return;
            }
            else
            {

                gBoxBind.Enabled = true;
                gBoxAccessce.Enabled = true;
                gBoxWriteRead.Enabled = true;
                gBoxChoice.Enabled = false;
                gBoxCopy.Enabled = false;

                string strLog = "连接读写器 " + strComPort + "@" + nBaudrate.ToString();
                lrtxtLog.AppendText(strLog + "\n");
            }

            //处理界面元素是否有效
            //SetFormEnable(true);


            btnConnectRs232.Enabled = false;
            btnDisconnectRs232.Enabled = true;

            //设置按钮字体颜色
            btnConnectRs232.ForeColor = Color.Black;
            btnDisconnectRs232.ForeColor = Color.Indigo;
            SetButtonBold(btnConnectRs232);
            SetButtonBold(btnDisconnectRs232);
        }

        private void btnDisconnectRs232_Click(object sender, EventArgs e)
        {
            //处理串口断开连接读写器
            //while (reader.CloseCom())//ly-2020-问题
            //{
            //    Application.DoEvents();
            //}

            int result = reader.CloseCom();

            if(result == 1)
            {
                lrtxtLog.AppendText("连接已经断开\n");

                gBoxBind.Enabled = false;
                gBoxAccessce.Enabled = false;
                gBoxWriteRead.Enabled = false;

                //处理界面元素是否有效

                btnConnectRs232.Enabled = true;
                btnDisconnectRs232.Enabled = false;

                //设置按钮字体颜色
                btnConnectRs232.ForeColor = Color.Indigo;
                btnDisconnectRs232.ForeColor = Color.Black;
                SetButtonBold(btnConnectRs232);
                SetButtonBold(btnDisconnectRs232);
            }
            else
            {
                MessageBox.Show("断开失败了！");
            }

            
        }

        private void btnResetReader_Click(object sender, EventArgs e)
        {
            int nRet = reader.Reset(m_curSetting.btReadId);
            if (nRet != 0)
            {
                string strLog = "复位读写器失败";
                lrtxtLog.AppendText(strLog + "\n");
            }
            else
            {
                string strLog = "复位读写器";
                m_curSetting.btReadId = (byte)0xFF;
                lrtxtLog.AppendText(strLog + "\n");
            }
        }

        //读取版本号
        private void btnGetFirmwareVersion_Click(object sender, EventArgs e)
        {
            int result = reader.GetFirmwareVersion(m_curSetting.btReadId);
        }

        private void ProcessGetFirmwareVersion(Reader.MessageTran msgTran)
        {
            string strCmd = "取得读写器版本号";

            this.Invoke(new Action(() => {
                lrtxtLog.AppendText(strCmd + "\n");
            }));

            string strErrorCode = string.Empty;         

            if (msgTran.AryData.Length == 2)
            {
                m_curSetting.btMajor = msgTran.AryData[0];
                m_curSetting.btMinor = msgTran.AryData[1];
                m_curSetting.btReadId = msgTran.ReadId;

                
                RefreshReadSetting(msgTran.Cmd);
                
                return;
            }
            else if (msgTran.AryData.Length == 1)
            {
                strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[0]);
            }
            else
            {
                strErrorCode = "未知错误";
            }
            string strLog = strCmd + "失败，失败原因： " + strErrorCode;
            this.Invoke(new Action(() => {
                lrtxtLog.AppendText(strLog + "\n");
            }));

        }


        //这是一个非常巧妙的全局变量
        int record;
        //读取当前EPC
        private void button1_Click(object sender, EventArgs e)
        {
            textSetAccessEpcMatch.Clear();

            reader.GetRFIDEpc(m_curSetting.btReadId);

            record = 0;
        }
    
        private void ProcessGetRFIDEpc(Reader.MessageTran msgTran)
        {
            string strErrorCode = string.Empty;

            if (record < 1) 
            {
                if (msgTran.Cmd == 137)
                {
                    for (int i = 3; i < msgTran.AryData.Length-1; i++)
                    {
                        this.Invoke(new Action(() => {
                            textSetAccessEpcMatch.AppendText(msgTran.AryData[i].ToString("X2") + " ");
                        }));
                    }

                    record++;
                    return;
                }
            }

        }


        //选定标签
        private void btnSetAccessEpcMatch_Click(object sender, EventArgs e)
        {
            
            string[] reslut = CCommondMethod.StringToStringArray(textSetAccessEpcMatch.Text.ToUpper(), 2);
            

            if (reslut == null)
            {
                MessageBox.Show("请选择EPC号");
                return;
            }

            byte[] btAryEpc = CCommondMethod.StringArrayToByteArray(reslut, reslut.Length);

            m_curOperateTagBuffer.strAccessEpcMatch = textSetAccessEpcMatch.Text;
            
            
            reader.SetAccessEpcMatch(m_curSetting.btReadId, 0x00, Convert.ToByte(btAryEpc.Length), btAryEpc);
        }

        private void ProcessSetAccessEpcMatch(Reader.MessageTran msgTran)
        {
            string strCmd = "已选定/取消选定标签";
            string strErrorCode = string.Empty;

            if (msgTran.AryData.Length == 1)
            {
                if (msgTran.AryData[0] == 0x10)
                {
                    this.Invoke(new Action(() => {
                        lrtxtLog.AppendText(strCmd + "\n");
                    }));
                    return;
                }
                else
                {
                    strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[0]);
                }
            }
            else
            {
                strErrorCode = "未知错误";
            }

            string strLog = strCmd + "失败，失败原因： " + strErrorCode;

            this.Invoke(new Action(() => {
                lrtxtLog.AppendText(strLog + "\n");
            }));
        }

        //取消选定
        private void btnUnsetAccessEpcMatch_Click(object sender, EventArgs e)
        {
            string[] reslut = CCommondMethod.StringToStringArray(textSetAccessEpcMatch.Text.ToUpper(), 2);

            if (reslut == null)
            {
                MessageBox.Show("请选择EPC号");
                return;
            }

            byte[] btAryEpc = CCommondMethod.StringArrayToByteArray(reslut, reslut.Length);

            m_curOperateTagBuffer.strAccessEpcMatch = textSetAccessEpcMatch.Text;


            reader.SetAccessEpcMatch(m_curSetting.btReadId, 0x01, Convert.ToByte(btAryEpc.Length), btAryEpc);
        }


        //读标签
        private void btnReadTag_Click_1(object sender, EventArgs e)
        {
            try
            {
                byte btMemBank = 0x01;
                byte btWordAdd = 0x02;
                byte btWordCnt = 0x04;

                

                //string[] reslut = CCommondMethod.StringToStringArray(htxtReadAndWritePwd.Text.ToUpper(), 2);

                /*if (reslut != null && reslut.GetLength(0) != 4)
                {
                    MessageBox.Show("密码必须是空或者4个字节");
                    return;
                }*/
                byte[] btAryPwd = new byte[4];
                btAryPwd[0] = 0x00;
                btAryPwd[1] = 0x00;
                btAryPwd[2] = 0x00;
                btAryPwd[3] = 0x00;


                /*if (reslut != null)
                {
                    btAryPwd = CCommondMethod.StringArrayToByteArray(reslut, 4);
                }*/

                m_curOperateTagBuffer.dtTagTable.Clear();
                //ltvOperate.Items.Clear();
                reader.ReadTag(m_curSetting.btReadId, btMemBank, btWordAdd, btWordCnt, btAryPwd);
                //WriteLog(lrtxtLog, "读标签", 1);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void ProcessReadTag(Reader.MessageTran msgTran)
        {
            string strCmd = "读标签";
            string strErrorCode = string.Empty;

            this.Invoke(new Action(() => {
                textReadEpc.Clear();
            }));

            if (msgTran.AryData.Length == 1)
            {
                strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[0]);
                string strLog = strCmd + "失败，失败原因： " + strErrorCode;

                this.Invoke(new Action(() => {
                    lrtxtLog.AppendText(strLog + "\n");
                }));
            }
            else
            {
                int nLen = msgTran.AryData.Length;
                int nDataLen = Convert.ToInt32(msgTran.AryData[nLen - 3]);
                int nEpcLen = Convert.ToInt32(msgTran.AryData[2]) - nDataLen - 4;

                string strPC = CCommondMethod.ByteArrayToString(msgTran.AryData, 3, 2);
                string strEPC = CCommondMethod.ByteArrayToString(msgTran.AryData, 5, nEpcLen);

                string strCRC = CCommondMethod.ByteArrayToString(msgTran.AryData, 5 + nEpcLen, 2);
                string strData = CCommondMethod.ByteArrayToString(msgTran.AryData, 7 + nEpcLen, nDataLen);


                this.Invoke(new Action(() => {
                    lrtxtLog.AppendText("当前标签的数据为:\n"+strData + "\n");
                }));

                this.Invoke(new Action(() => {
                    textReadEpc.AppendText(strData + "\n");
                }));


                byte byTemp = msgTran.AryData[nLen - 2];
                byte byAntId = (byte)((byTemp & 0x03) + 1);
                string strAntId = byAntId.ToString();

                string strReadCount = msgTran.AryData[nLen - 1].ToString();

                DataRow row = m_curOperateTagBuffer.dtTagTable.NewRow();
                row[0] = strPC;
                row[1] = strCRC;
                row[2] = strEPC;
                row[3] = strData;
                row[4] = nDataLen.ToString();
                row[5] = strAntId;
                row[6] = strReadCount;

                m_curOperateTagBuffer.dtTagTable.Rows.Add(row);
                m_curOperateTagBuffer.dtTagTable.AcceptChanges();
                //RefreshOpTag(0x81);
                //WriteLog(lrtxtLog, strCmd, 0);
            }
        }


        //写标签
        private void btnWriteTag_Click(object sender, EventArgs e)
        {
            try
            {
                byte btMemBank = 0x01;
                byte btWordAdd = 0x02;
                byte btWordCnt = 0x04;
                byte btCmd = 0x82;

                byte[] btAryPwd = new byte[4];
                btAryPwd[0] = 0x00;
                btAryPwd[1] = 0x00;
                btAryPwd[2] = 0x00;
                btAryPwd[3] = 0x00;

                String[] reslut = CCommondMethod.StringToStringArray(htxtWriteData.Text.ToUpper(), 2);

                if (reslut == null)
                {
                    MessageBox.Show("输入字符无效");
                    return;
                }
                byte[] btAryWriteData = CCommondMethod.StringArrayToByteArray(reslut, reslut.Length);
                btWordCnt = Convert.ToByte(reslut.Length / 2 + reslut.Length % 2);


                m_curOperateTagBuffer.dtTagTable.Clear();
                //ltvOperate.Items.Clear();
                reader.WriteTag(m_curSetting.btReadId, btAryPwd, btMemBank, btWordAdd, btWordCnt, btAryWriteData, btCmd);
                //WriteLog(lrtxtLog, "写标签", 0);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private int WriteTagCount = 0;
        private void ProcessWriteTag(Reader.MessageTran msgTran)
        {
            string strCmd = "写标签";
            string strErrorCode = string.Empty;

            if (msgTran.AryData.Length == 1)
            {
                strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[0]);
                string strLog = strCmd + "失败，失败原因： " + strErrorCode;

                this.Invoke(new Action(() => {
                    lrtxtLog.AppendText(strLog + "\n");
                }));
            }
            else
            {
                int nLen = msgTran.AryData.Length;
                int nEpcLen = Convert.ToInt32(msgTran.AryData[2]) - 4;

                if (msgTran.AryData[nLen - 3] != 0x10)
                {
                    strErrorCode = CCommondMethod.FormatErrorCode(msgTran.AryData[nLen - 3]);
                    string strLog = strCmd + "失败，失败原因： " + strErrorCode;

                    this.Invoke(new Action(() => {
                        lrtxtLog.AppendText(strLog + "\n");
                    }));
                    return;
                }
                WriteTagCount++;

                this.Invoke(new Action(() => {
                    lrtxtLog.AppendText("重写成功！\n");
                }));

                string strPC = CCommondMethod.ByteArrayToString(msgTran.AryData, 3, 2);
                string strEPC = CCommondMethod.ByteArrayToString(msgTran.AryData, 5, nEpcLen);
                string strCRC = CCommondMethod.ByteArrayToString(msgTran.AryData, 5 + nEpcLen, 2);
                string strData = string.Empty;

                byte byTemp = msgTran.AryData[nLen - 2];
                byte byAntId = (byte)((byTemp & 0x03) + 1);
                string strAntId = byAntId.ToString();

                string strReadCount = msgTran.AryData[nLen - 1].ToString();

                DataRow row = m_curOperateTagBuffer.dtTagTable.NewRow();
                row[0] = strPC;
                row[1] = strCRC;
                row[2] = strEPC;
                row[3] = strData;
                row[4] = string.Empty;
                row[5] = strAntId;
                row[6] = strReadCount;

                m_curOperateTagBuffer.dtTagTable.Rows.Add(row);
                m_curOperateTagBuffer.dtTagTable.AcceptChanges();

                //RefreshOpTag(0x82);
                //WriteLog(lrtxtLog, strCmd, 0);
                if (WriteTagCount == (msgTran.AryData[0] * 256 + msgTran.AryData[1]))
                {
                    WriteTagCount = 0;
                }
            }
        }


        //标签绑定物品代码开始了！
        
        //连接数据库
        private void Oracle_Connection_Click(object sender, EventArgs e)
        {
            String port = null, host = null, serverName = null, userName = null, password = null;

            if(""== tbPort.Text)
            {
                MessageBox.Show("请输入主机名");
                return;
            }
            port = tbPort.Text;

            if ("" == tbHost.Text)
            {
                MessageBox.Show("请输入端口号");
                return;
            }
            host = tbHost.Text;

            if("" == tbServerName.Text)
            {
                MessageBox.Show("请输入服务名");
                return;
            }
            serverName = tbServerName.Text;

            if ("" == tbUserName.Text)
            {
                MessageBox.Show("请输入用户名");
                return;
            }
            userName = tbUserName.Text;

            if("" == tbPassword.Text)
            {
                MessageBox.Show("请输入密码");
                return;
            }
            password = tbPassword.Text;

            string result = dbconn.Connect(port, host, serverName, userName, password);

            if(result.Length == 8)
            {
                gBoxChoice.Enabled = true;
                gBoxCopy.Enabled = true;
            }

            lrtxtLog.AppendText(result + "\r\n");
            MessageBox.Show(result);


        }

        private void Oracle_Close_Click(object sender, EventArgs e)
        {
            string result = dbconn.Oracle_Close();
            lrtxtLog.AppendText(result + "\r\n");
            MessageBox.Show(result);

            tbPort.Clear();
            tbHost.Clear();
            tbServerName.Clear();
            tbUserName.Clear();
            tbPassword.Clear();

            gBoxChoice.Enabled = false;
            gBoxCopy.Enabled = false;

        }

        private void btClear1_Click(object sender, EventArgs e)
        {
            rb1.Checked = false;
            rb2.Checked = false;
            rb3.Checked = false;
            rb4.Checked = false;

            tbiName.Text = "";
        }


        //Copy三个标签。
        private void btnCopy1_Click(object sender, EventArgs e)
        {
            if ("" == textSetAccessEpcMatch.Text)
            {
                MessageBox.Show("请在左侧先选定一个标签！！");
                return;
            }

            tbCopy1.Text = textSetAccessEpcMatch.Text;
        }

        private void btnCopy2_Click(object sender, EventArgs e)
        {
            if ("" == textSetAccessEpcMatch.Text)
            {
                MessageBox.Show("请先在左侧选定标签！！");
                return;
            }
            if("" == tbCopy1.Text)
            {
                MessageBox.Show("请先从标签1开始Copy标签！！");
                return;
            }
            

            tbCopy2.Text = textSetAccessEpcMatch.Text;

            if (tbCopy1.Text == tbCopy2.Text)
            {
                MessageBox.Show("标签2与标签1Copy重复！！");
                tbCopy2.Text = "";
                return;
            }

        }

        private void btnCopy3_Click(object sender, EventArgs e)
        {
            if ("" == textSetAccessEpcMatch.Text)
            {
                MessageBox.Show("请先在左侧选定标签！！");
                return;
            }
            if ("" == tbCopy1.Text)
            {
                MessageBox.Show("请先从标签1开始Copy标签！！");
                return;
            }
            if ("" == tbCopy2.Text)
            {
                MessageBox.Show("请先从标签2开始Copy标签！！");
                return;
            }

            tbCopy3.Text = textSetAccessEpcMatch.Text;

            if (tbCopy1.Text == tbCopy3.Text)
            {
                MessageBox.Show("标签3与标签2Copy重复！！");
                tbCopy3.Text = "";
                return;
            }

            if (tbCopy3.Text == tbCopy2.Text)
            {
                MessageBox.Show("标签3与标签1Copy重复！！");
                tbCopy3.Text = "";
                return;
            }

        }


        //提交绑定事务
        private void tbSubmit_Click(object sender, EventArgs e)
        {

            string itemName = "";
            string nowTime = DateTime.Now.ToString();

            if("" == policeNo.Text) {
                MessageBox.Show("请输入警号！！");
                return;
            }

            foreach (Control c in gBoxChoice.Controls)
            {
                if ((c is RadioButton) && (c as RadioButton).Checked)
                {
                    itemName = c.Text;
                    
                }
            }

            if (itemName == "")
            {
                itemName = tbiName.Text;

            }

            if("" == itemName)
            {
                MessageBox.Show("请先选择或输入一个物品名称！！");
                return;
            }

            if("" == tbCopy1.Text)
            {
                MessageBox.Show("请至少Copy一个标签！！");
                return;
            }

            int sqlNum = 0;
            string sql_insert1 = "";
            string sql_insert2 = "";
            string sql_insert3 = "";

            string s1 = tbCopy1.Text;
            s1 = s1.Substring(0, s1.Length - 1);
           
            sql_insert1 = "insert into GC_EQUIPMENT(ID,EQUIPMENT_NAME,TAG,POLICE_NUMBER,STATUS) values(SEQ_GC_EQUIPMENT.NEXTVAL,'" + itemName + "','" + s1 + "','" + policeNo.Text + "','4')";
            sqlNum = sqlNum + 1;
            
            string param = "{\"equipmentName\":\""+ itemName + "\",\"tag\":\"" + s1 + "\",\"policeNumber\":\"" + policeNo.Text + "\"}";
            //MessageBox.Show(param);

            if (tbCopy2.Text != "")
            {
                string s2 = tbCopy2.Text;
                s2 = s2.Substring(0, s2.Length - 1);
                
                sql_insert2 = "insert into GC_EQUIPMENT(ID,EQUIPMENT_NAME,TAG,POLICE_NUMBER,STATUS) values(SEQ_GC_EQUIPMENT.NEXTVAL,'" + itemName + "','" + s2 + "','" + policeNo.Text + "','4')";
                sqlNum = sqlNum + 1;
            }

            if (tbCopy3.Text != "")
            {
                string s3 = tbCopy3.Text;
                s3 = s3.Substring(0, s3.Length - 1);
                sql_insert3 = "insert into GC_EQUIPMENT(ID,EQUIPMENT_NAME,TAG,POLICE_NUMBER,STATUS) values(SEQ_GC_EQUIPMENT.NEXTVAL,'" + itemName + "','" + s3 + "','" + policeNo.Text + "','4')";
                sqlNum = sqlNum + 1;
            }

            //弹出确认框让用户确认
            DialogResult dr = MessageBox.Show("是否提交警号为:‘" + policeNo.Text + "’物品名称为:‘" + itemName + "’的这" + sqlNum + "组绑定？", "Are you sure???", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.OK)
            {
                
                //点确定的代码
                tbCopy1.Text = "";
                tbCopy2.Text = "";
                tbCopy3.Text = "";
                tbiName.Text = "";

                string equipRegistUrl = "http://218.2.157.29:9999/equipment/equipmentManage/insertEquipment";
                string httpRes = HttpHelper.HttpPost(equipRegistUrl, param);
                if(httpRes != null)
                {
                    if (httpRes.Equals("erro"))
                    {
                        MessageBox.Show("绑定失败，请检查网络！");
                    }
                    else
                    {
                        MessageBox.Show(httpRes);
                    }
                    
                }


                //string result = dbconn.Oracle_Insdelupd(sql_insert1, sql_insert2, sql_insert3);
                //MessageBox.Show(result);
            }
            else
            {        //点取消的代码
            }

        }

        
    }
}
